package com.jtfr.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jtfr.pojo.User;
import com.jtfr.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {
	
	private static Logger LOGGER = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserService userService;
	
	@RequestMapping(value="/addUser", method=RequestMethod.POST)
	public int addUser(@RequestBody User user) {
		return userService.addUser(user);
	}
	
	@GetMapping("/findAllUser")
	public Object findAllUser(
            @RequestParam(name = "pageNum", required = false, defaultValue = "1")
                    int pageNum,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10")
                    int pageSize){
		// 这里返回一个分页对象，包含数据，数据总数等，方便前端处理
		LOGGER.info("/findAllUser");
		return userService.findAllUser(pageNum, pageSize);
	}
}
